package cn.hrlly.tao2shou.presenter;

import cn.hrlly.tao2shou.biz.PublishCommodityBiz;
import cn.hrlly.tao2shou.biz.PublishCommodityBizImpl;
import cn.hrlly.tao2shou.domain.Commodity;
import cn.hrlly.tao2shou.listener.OnPublishCommodityListener;
import cn.hrlly.tao2shou.view.view_interface.PublishCommodityView;

/**
 * User: gengliang
 * Date: 2016-01-27
 * Time: 13:39
 */

public class PublishCommodityPresenterImpl implements  PublishCommodityPresenter,OnPublishCommodityListener {

    private PublishCommodityBiz publishCommodityBiz;
    private PublishCommodityView publishCommodityView;

    public PublishCommodityPresenterImpl(PublishCommodityView publishCommodityView){
        this.publishCommodityBiz=new PublishCommodityBizImpl(this);
        this.publishCommodityView=publishCommodityView;
    }

    @Override
    public void publishCommodity() {
        Commodity commodity=new Commodity();
        commodity.setCommodityName(publishCommodityView.getCommodityName());
        commodity.setCommodityCount(publishCommodityView.getCommodityCount());
        commodity.setClassification(publishCommodityView.getClassification());
        commodity.setExpectedPrice(publishCommodityView.getExpectedPrice());
        commodity.setBarterDescription(publishCommodityView.getBarterDescription());
        commodity.setNewDegree(publishCommodityView.getNewDegree());
        commodity.setCommodityDescription(publishCommodityView.getCommodityDescription());
        commodity.setExpectedTime(publishCommodityView.getExpectedTime());
        commodity.setExpectedLocation(publishCommodityView.getExpectedLocation());
        publishCommodityBiz.publishCommodity(commodity,publishCommodityView.getCommodityPhotos());
    }

    @Override
    public void publishCommoditySucc(String message) {
        publishCommodityView.clearAll();
        publishCommodityView.showMessage(message);
    }

    @Override
    public void publishCommoditySucc(int message) {
        publishCommodityView.clearAll();
        publishCommodityView.showMessage(message);
    }

    @Override
    public void publishCommodityFail(int errorMessage) {
        publishCommodityView.showMessage(errorMessage);
    }

    @Override
    public void publishCommodityFail(String errorMessage) {
        publishCommodityView.showMessage(errorMessage);
    }
}
